#!/usr/bin/env python.exe

#Script to use the Fisher Scientific PPS4102 Top Pan balance in ROS

import rospy
import sys
from fisherbrand_pps4102_balance_driver.fisher_balance_ros_driver import BalanceDriverROS
            
if __name__ == "__main__": #Object oriented initialization for ROS
    if len(sys.argv) > 1:
        port = sys.argv[1]
    else:
        port = '/dev/ttyUSB0'
        rospy.logerr('No input serial port is provided. The default serial port (ttyUSB0) is used')
    rospy.init_node("scale_driver", anonymous=True) #initialize rospy node
    port = sys.argv[1]
    balance_ROS = BalanceDriverROS(port) #Create instance of ROS Wrapper
    balance_ROS.on() #Turn on scale (in case turned off)
    rospy.on_shutdown(balance_ROS.off) #Turn off scale when driver is turned off
    rospy.loginfo("Balance driver started")
    rospy.spin()
